using UnityEngine;
using System.Collections;

public class CheckboxControlledComponent : MonoBehaviour {
	public GameObject target;
	public bool inverse = false;

	bool mUsingDelegates = false;

	void Start ()
	{
		UICheckbox chk = GetComponent<UICheckbox>();

		if (chk != null)
		{
			mUsingDelegates = true;
			chk.onStateChange += OnActivateDelegate;
		}
	}

	void OnActivateDelegate (bool isActive)
	{
		//if (enabled && target != null) target.enabled = inverse ? !isActive : isActive;
		
		UITweener tweener = target.GetComponent<UITweener>();
		if(tweener) tweener.Play(inverse ? !isActive : isActive);
	}

	/// <summary>
	/// Legacy functionality -- keeping it for backwards compatibility.
	/// </summary>

	void OnActivate (bool isActive) { if (!mUsingDelegates) OnActivateDelegate(isActive); }
	
}
